﻿Ext.onReady(function () {
    Ext.apply(Kwan, {
        def: Collection
    });
});
Ext.apply(Kwan, {
    CLColor: ['red', 'blue', 'green', 'red', 'blue', 'blue', 'blue'],
    CLTips: ['系统作废', '未结账', '已结账', '已冲红', '已挂账', '已换房', '已免受'],
    ClStatus: function (d) {
        var template = '<span style="color:{0};">{1}</span>';
        return String.format(template, Kwan.CLColor[d], Kwan.CLTips[d]);
    },
    GVEL: function (d, rowParams) {
        var html = '<div style=\'padding:0 5px 5px 5px;\'><i>{0}</i>.<br /><b>Price: {1}</b></div>';
        rowParams.body = String.format(html, d.RoomRoomNO, Ext.util.Format.usMoney(d.TotalPrice));
    },
    search: function (index) {
        var roomNO = qRoomNO.getValue(),
                startDate = Ext.util.Format.date(qStartDate.getValue(), 'Y-m-d'),
                endDate = Ext.util.Format.date(qEndDate.getValue(), 'Y-m-d');
        if (index == 0) {
            qRoomNO.reset();
            txtFilter.setValue('');
            qRoomNO.triggers[0].hide();
        }
        else {
            var val = "";
            val += (roomNO.length > 0 ? roomNO : "") + ",";
            val += (startDate.length > 0 ? startDate : "") + ",";
            val += (endDate.length > 0 ? endDate : "") + ",";
            txtFilter.setValue(val);
        }
    },
    showCorrectConfirm: function (obj, record) {
        return Ext.Msg.confirm(this.PROMPTED, "确定要冲红选中的账单吗？", function (btn) {
            if (btn == "yes") { obj.CorrectOrder(record); }
        });
    },
    correct: function (d) {
        if (d.length < 1) { this.showNotify(this.PROMPTEDERR_NOSELECT, this.ERR_NOSELECT); return; }
        else {
            this.showCorrectConfirm(this.def, this.GetIDs(d));
        }
    }
});